package priv.abadstring.study.haoke.dubbo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import priv.abadstring.study.haoke.dubbo.entity.HouseResources;
import priv.abadstring.study.haoke.dubbo.service.BaseServiceImpl;
import priv.abadstring.study.haoke.dubbo.service.HouseResourcesService;
import priv.abadstring.study.haoke.dubbo.dto.PageInfo;

/**
 * BaseServiceImpl
 *
 * @author aBadString
 * @date 2021-06-15 15:21:26
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class HouseResourcesServiceImpl extends BaseServiceImpl<HouseResources> implements HouseResourcesService {
    @Override
    public int saveHouseResources(HouseResources houseResources) {
        if (StringUtils.isBlank(houseResources.getTitle())) {
            return -1;
        }
        return super.save(houseResources);
    }

    @Override
    public PageInfo<HouseResources> listHouseResources(int page, int pageSize, HouseResources queryCondition) {
        QueryWrapper<HouseResources> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("updated");
        IPage<HouseResources> pageList = super.queryPageList(wrapper, page, pageSize);
        return new PageInfo<>(
                (int) pageList.getTotal(),
                (int) pageList.getCurrent(),
                (int) pageList.getSize(),
                pageList.getRecords()
        );
    }

    @Override
    public HouseResources getById(Long id) {
        return super.queryById(id);
    }

    @Override
    public boolean updateHouseResources(HouseResources houseResources) {
        return super.update(houseResources) == 1;
    }
}
